﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<List<object>>" %>

<asp:Content ID="mainContent" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
    <table width="60%" border="0" cellspacing="2" cellpadding="2" class="datatable">
        
        <% foreach (var item in Model)
           {
                           
        %>
        <tr style="display:none;">
       <%-- <tr>--%>
            <td id="dato">
                <%= Html.Encode(item) %>
            </td>
        </tr>
        <% } %>
    </table>

   <%-- <input value="Ver en Lista" type="button" onclick="lista($('#dato').text());"/>--%>
   
    <br />
     <div id="map_canvas" style="width: 100%; height: 650px">
    </div>
</asp:Content>

<asp:Content ID="headContent" ContentPlaceHolderID="HeadContentPlaceHolder" runat="server">
<script type="text/javascript" src="<%= ResolveUrl("~") %>Content/Mapa/dragzoom.js" ></script>

<script type="text/javascript">

    function lista() {
    var linea=$('#dato').text();
     //alert(linea);
    var cadena=linea+"?";
    var elem=cadena.split('?');

    //var uno=elem[0];
    var dos=elem[1];
    //var tres=elem[2];
   
    //alert(uno);
    //alert(dos);
    //alert(tres);
    
    document.location.href = "<%= ResolveUrl("~") %>Home/Index/?"+dos;

    
    }
   function initialize() {

        //alert($("#dato").text());
        var dato;
        dato = $("#dato").text();

        //alert(dato);
        
        $.ajax({
                type: "POST",
                url: dato,
                //data: "Id="+id+"&fecha_desde='"+fecha_desde+"'&fecha_hasta='"+fecha_hasta+"'",
                dataType: "json",
                cache: false,
                success: function (response) {
                    //entre suscces
                    //alert(response);
                    if (GBrowserIsCompatible()) {
                        var map = new GMap2(document.getElementById("map_canvas"));
                        //map.setMapType(G_HYBRID_MAP);
                        map.addMapType(G_SATELLITE_3D_MAP);
                         map.addControl(new DragZoomControl());
                        var baseIcon = new GIcon();
                        baseIcon.iconSize = new GSize(60, 60);
                        baseIcon.shadowSize = new GSize(56, 32);
                        baseIcon.iconAnchor = new GPoint(16, 32);
                        baseIcon.infoWindowAnchor = new GPoint(16, 0);
                        //var edificio = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/CabrioletRedblanco.png", null, "<%= ResolveUrl("~") %>Content/Images/CabrioletRedblancos.png");
                        var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/Flechas-180.gif", null, "<%= ResolveUrl("~") %>Content/Images/Flechas-180s.gif");
                        
                        //var center = new GLatLng(data[0], data[1]);
                        var center0=new GLatLng();
                        var pol = new Array();
                         $.each(response, function(i, data) {

                           //alert (center1);
                            var center = new GLatLng(data.Latitud, data.Longitud);
                            var center0=center;
                           
                            if(data.Grados==0)
                        {
                            sentido="N";

                            if (data.Velocidad>5)
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeN.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeNs.png");
                            }
                             else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaN.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaNs.png");
                            
                            }
                            else
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopN.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopNs.png");
                            }
                        }
                        
                        if ((data.Grados>0) && (data.Grados<90))
                        {
                            
                            sentido="NE";
                            
                            if (data.Velocidad>5)
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeNe.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeNes.png");
                            }
                             else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaNe.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaNes.png");
                            
                            }
                            else
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopNe.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopNes.png");
                            }

                        }
                        if(data.Grados==90)
                        {
                        
                        sentido="E";
                       
                        if (data.Velocidad>5)
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeE.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeEs.png");
                            }
                             else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaE.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaEs.png");
                            
                            }
                            else
                            {
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopE.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopEs.png");
                            }
                        
                        }
                        if((data.Grados>90) && (data.Grados<180))
                        {
                        
                         sentido="SE";   
                        
                          if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeSe.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeSes.png");
                         }
                          else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaSe.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaSes.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopSe.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopSes.png");
                          }  

                        }
                        if(data.Grados==180)
                        {
                        
                        sentido="S";
                        
                        if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeS.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeSs.png");
                        }
                         else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaS.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaSs.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopS.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopSs.png");
                          }
                        
                        }
                        if((data.Grados>180) && (data.Grados<270))
                        {
                        
                         sentido="SW";   
                         
                          if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeSw.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeSws.png");
                         }
                          else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaSw.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaSws.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopSw.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopSws.png");
                         }

                        }
                        if(data.Grados==270)
                        {
                        
                        sentido="W";
                        
                         if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeW.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeWs.png");
                        }
                         else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaW.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaWs.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopW.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopWs.png");
                            }
                        
                        }
                        if((data.Grados>270) && (data.Grados<360))
                        {
                        
                         sentido="NW";   
                         
                         if (data.Velocidad>5)
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeNW.png", null, "<%= ResolveUrl("~") %>Content/Images/cvFlecha/VerdeNWs.png");
                         }
                          else if(data.Evento!=1)
                            {
                            
                                var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaNw.png", null, "<%= ResolveUrl("~") %>Content/Images/emerFlecha/EmergenciaNw.png");
                            
                            }
                         else
                         {
                            var flecha = new GIcon(baseIcon, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopNW.png", null, "<%= ResolveUrl("~") %>Content/Images/stopFlecha/StopNWs.png");
                         }

                        }


                            map.setCenter(center, 11);
                            var marker = new GMarker(center,flecha);
                            
                            


                             map.addOverlay(marker);

                             var sentido;

                        

                             
                            //marker.openInfoWindowHtml("<b style='color: #0000FF'>POSICION "+ i +"</b><br/><b>Alias: </b><i>" + data.NombreUnidad + "</i><br/><b>Placa: </b><i>" + data.PlacaUnidad + "</i><br/><b>Fecha/Hora: </b><i>" + data.Fecha + "</i><br/><b>Velocidad: </b><i>" + data.Velocidad   +" " +"Kph</i><br/><b>Sentido: </b><i>(" + data.Grados +")"+sentido+ "</i><br/><b>Evento: </b><i>" + data.EventoNombre + "</i>");
                            GEvent.addListener(marker, "click", function () {
                            marker.openInfoWindowHtml("<b style='color: #0000FF'>POSICION "+ i +"</b><br/><b>Alias: </b><i>" +data.NombreUnidad + "</i><br/><b>Placa: </b><i>" + data.PlacaUnidad + "</i><br/><b>Fecha/Hora: </b><i>" +data.Fecha + "</i><br/><b>Velocidad: </b><i>" + data.Velocidad +" " +"Kph</i><br/><b>Sentido: </b><i>(" + data.Grados +")"+ sentido+"</i><br/><b>Evento: </b><i>" + data.EventoNombre + "</i><br/><a href='javascript:lista()'>Ver en Lista</a>");
                            });//fin funcion click
                          

                                

                                 //pol[i]=center0;

                              

                         
                         });//fir iteracion

                         //alert("pol"+pol[5]);
//                         var polyline = new GPolyline(pol, "#ff0000", 5); 
//                         map.addOverlay(polyline);

                         map.setUIToDefault();
                         map.enableRotation();
                    }


                  


                //terminado success
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("error: "+XMLHttpRequest.responseText);
                }
            });

    }

       

    $(window).load(function () {
        initialize();
    });

    $(window).unload(function () {
        GUnload();
    });
    </script>
    

</asp:Content>

<asp:Content ID="menuContent" ContentPlaceHolderID="MenuContentPlaceHolder" runat="server">
</asp:Content>
